﻿#pragma once

#include "HashTable.h"

namespace ljh
{
	template<class K, class Hash = HashFunc<K>>
	class unordered_set
	{
		struct SetOfT
		{
			const K& operator()(const K& key)
			{
				return key;
			}
		};

	public:

		typedef typename hash_bucket::HashTable<K, const K, Hash, SetOfT>::Iterator iterator;
		typedef typename hash_bucket::HashTable<K, const K, Hash, SetOfT>::ConstIterator const_iterator;

		iterator begin()
		{
			return _ht.Begin();
		}

		iterator end()
		{
			return _ht.End();
		}

		const_iterator begin()const
		{
			return _ht.Begin();
		}

		const_iterator end()const
		{
			return _ht.End();
		}

		pair<iterator, bool> Insert(const K& key)
		{
			return _ht.Insert(key);
		}

		bool Erase(const K& key)
		{
			return _ht.Erase(key);
		}

		iterator Find(const K& key)
		{
			return _ht.Find(key);
		}


	private:
		hash_bucket::HashTable<K, const K, Hash, SetOfT> _ht;

	};


	void test_set()
	{
		unordered_set<int> s;
		int a[] = { 4, 2, 6, 1, 3, 5, 15, 7, 16, 14, 3,3,15 };
		for (auto e : a)
		{
			s.Insert(e);
		}
		for (auto e : s)
		{
			cout << e << " ";
		}
		cout << endl;

		unordered_set<int>::iterator it = s.begin();
		while (it != s.end())
		{
			// 不⽀持修改
			//*it += 1;
			cout << *it << " ";
			++it;
		}
		cout << endl;
	}
}